package view.test;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;

import javax.swing.JPanel;

/**
 * This is a panel that spans all other components
 * on the mainPanel. Its sole purpose as of now
 * is to overlay the drag/drop image. 
 * 
 * THIS SHALL NOT CATCH ANY AWT EVENTS
 * i.e no ActionListeners allowed
 * Events are caught by the component with
 * the next highest z order and notify this 
 * accordingly.
 */
public class GlassPane extends JPanel {
	
	private Image cursorImage;
	private Point cursorPoint = new Point();

	private static final long serialVersionUID = 1L;

	public GlassPane (Dimension dimension) {
		
		this.setSize(dimension);
		this.setMinimumSize(dimension);
		this.setOpaque(false);
		
	}
	
	@Override
	public void paintComponent(Graphics g) {
		
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		
		
		if (cursorImage == null)
			return;
		
		int imgX = cursorImage.getWidth(this) / 2;
		int imgY = cursorImage.getHeight(this) / 2;
		
		g2.drawImage(cursorImage, cursorPoint.x - imgX, cursorPoint.y - imgY, this);
		
	}

	public Point getCursorPoint() {
		return cursorPoint;
	}

	public void setCursorPoint(Point cursorPoint) {
		this.cursorPoint = cursorPoint;
	}

	public void setCursorImage(Image cursorImage) {
		this.cursorImage = cursorImage;
	}
	
}
